package com.web.cms.ad.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;

import com.web.cms.ad.message.AdvPosRequest;
import com.web.cms.ad.message.AdvPosResponse;
import com.web.cms.ad.model.AdvPos;

/**
 * 广告位置转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年11月13日
 */
public class AdvPosConvertor
{
	private AdvPosConvertor()
	{
	}
	
	public static AdvPos toAdvPos(AdvPosRequest request)
	{
		if (request == null)
			return null;
		
		AdvPos advPos = new AdvPos();
		advPos.setId(request.getId());
		advPos.setWebId(request.getWebId());
		advPos.setCode(request.getCode());
		advPos.setName(request.getName());
		advPos.setDescp(request.getDescp());
		advPos.setType(request.getType());
		advPos.setState(request.getState());
		return advPos;
	}
	
	public static List<AdvPos> toAdvPos(List<AdvPosRequest> requestList)
	{
		List<AdvPos> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (AdvPosRequest request : requestList)
		{
			list.add(toAdvPos(request));
		}
		return list;
	}
	
	public static AdvPosResponse toResponse(AdvPos advPos)
	{
		if (advPos == null)
			return null;
		
		AdvPosResponse response = new AdvPosResponse();
		response.setId(advPos.getId());
		response.setWebId(advPos.getWebId());
		response.setCode(advPos.getCode());
		response.setName(advPos.getName());
		response.setDescp(advPos.getDescp());
		response.setType(advPos.getType());
		response.setState(advPos.getState());
		return response;
	}
	
	public static List<AdvPosResponse> toResponse(List<AdvPos> list)
	{
		List<AdvPosResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (AdvPos advPos : list)
		{
			responseList.add(toResponse(advPos));
		}
		return responseList;
	}
	
	public static Map<Integer, AdvPosResponse> toResponse(Map<Integer, AdvPos> map)
	{
		Map<Integer, AdvPosResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, AdvPos> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<AdvPosResponse> toResponse(Page<AdvPos> page)
	{
		if (page == null)
			return null;
		
		Page<AdvPosResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
